import os

import yaml

from common.logger import log
from common.logger import check_path

__all__ = ['get_settings', 'check_valid']


def check_valid(key, value):
    if not value:
        log.e('[%s] Not Configured.Please Config in settings.yaml.' % key)
        raise ValueError
    return value


def get_settings(yaml_file='setting.yml'):
    yaml_file = check_path(yaml_file)
    with open(yaml_file, 'r', encoding='utf-8') as f:
        return yaml.safe_load(f.read())
